package someTestExcemple.huaweiOd.container.stack;

//华为OD机试 - 消消乐游戏 - 栈Stack，通过Deque优化（Java 2023 B卷 100分）
//https://blog.csdn.net/guorui_java/article/details/133658829
import java.util.*;
public class StringErasure {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int n = str.length();
        Stack<Character> stack = new Stack<>();
        stack.push(str.charAt(0));
        int i=1;
        while(i<n) {
            char c = str.charAt(i);
            if(!stack.isEmpty()) {
                if(stack.peek() == c) {
                    //上一个元素和当前元素相同 需要消除
                    stack.pop();
                } else {
                    stack.push(c);
                }
            } else {
                stack.push(c);
            }
            i++;
        }
        System.out.println(stack.size());
    }
}
